#include <scwrapper.h>
#include <foolibc.h>

const int myport = 2;


void stdout(char *string) 
{
	prints(string);
}

void processing(char *string) {
	static int cnt = 0;
	char buf[200] = {0};
	my_itoa(cnt++, buf);
	my_strncat(buf, " ", sizeof(buf)/sizeof(buf[0]));
	my_strncat(buf, string, sizeof(buf)/sizeof(buf[0]));
	stdout(buf);
}

void stdin()
{
	struct message m;
	if (retrieve_msg(&m, myport) == 0) {
		processing(m.data);
		free((long) m.data);
	}
	terminate();
}

int main(int argc, char* argv[])
{
	const int status = create_mailbox(stdin, myport);
	if (status != ALL_OK) {
		while (1) {prints("Could not create mailbox1\n\0");}
	}
	
	while (1) {pause(100);}
}
